﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TaskLib
{
    public partial class SortableListView : ListView
    {
        protected int sortColumn;

        public SortableListView()
        {
            InitializeComponent();
        }

        protected override void OnColumnClick(ColumnClickEventArgs e)
        {
            if (e.Column != sortColumn)
            {
                sortColumn = e.Column;
                Sorting = SortOrder.Ascending;
            }
            else
            {
                if (Sorting == SortOrder.Ascending)
                {
                    Sorting = SortOrder.Descending;
                }
                else
                {
                    Sorting = SortOrder.Ascending;
                }
            }

            Sort();

            this.ListViewItemSorter = new ListViewItemComparer(e.Column, Sorting);

            base.OnColumnClick(e);
        }
    }
}
